import {legacy_createStore,applyMiddleware} from "redux"
import thunk from "redux-thunk"
import logger from "redux-logger"
import {ALLSTATE,ALLLIST} from "../types/home"
let initiaState={
arr:[],
classarr:[]
}

function reducer(state:ALLSTATE=initiaState, {type,payload}:any) {
    let newarr=JSON.parse(JSON.stringify(state.arr))
    let newclassarr=JSON.parse(JSON.stringify(state.classarr))
  switch (type) {
   
    case "setlist":
        newarr=payload
    
      return {
          ...state,
        arr: newarr
      }
      case "classList":
     newclassarr=payload
    return {
            ...state,
            classarr:newclassarr
    }
   case "ssearch" :
      let searcharr=newarr.filter((item:any) => {
        return item.name.includes(payload)
      })
      return {
        ...state,
        arr:searcharr
      }

    default:
     return {...state}
  }
}
const store =legacy_createStore(reducer,applyMiddleware(thunk,logger))
export default store


